package com.dayuanit.dy15.atm.holder;

public class PageHolder<T> {
    //总页数
    private int totalPage;
    //当前页
    private int currentPage;
    //每页个数
    private int pageSize = 2;
    //每页显示的数据
    private T data;

    private int offset;

    //总条数
    private int total;

    private PageHolder(int currentPage, int total) {
        this.currentPage = currentPage;
        this.offset = (currentPage - 1) * pageSize;
        this.totalPage = total % pageSize == 0 ? total / pageSize : total / pageSize + 1;
        this.total = total;
    }

    private PageHolder(int currentPage, int total, int pageSize) {
        this.currentPage = currentPage;
        this.offset = (currentPage - 1) * pageSize;
        this.totalPage = total % pageSize == 0 ? total / pageSize : total / pageSize + 1;
        this.pageSize = pageSize;
        this.total = total;
    }

    public static PageHolder init(int currentPage, int total) {
        return new PageHolder(currentPage, total);
    }

    public static PageHolder init(int currentPage, int total, int pageSize) {
        return new PageHolder(currentPage, total, pageSize);
    }

    public int getTotal() {
        return total;
    }

    public int offset() {
        return offset;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
